home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / WINDBOX.C < prev    next >
C/C++ Source or Header  |  1991-02-04  |  11KB  |  451 lines

  1. #include "pt.h"
  2. #include "string.h"
  3.  
  4. extern struct window *windows;
  5. extern struct window *windowList;
  6.  
  7. void pascal
  8. /* XTAG:initWindows */
  9. initWindows()
  10. {
  11.     extern struct window *hiddenList;
  12.     extern unsigned char charTable[];
  13.     extern int maxFiles;
  14.  
  15.     register int i;
  16.  
  17.     for(i = 0; i < maxFiles; i++)
  18.         windows[i].state = 0;
  19.     windowList = NULL;
  20.     hiddenList = NULL;
  21.     charTable['\n'] = 1;
  22.     charTable[0] = 2;
  23.     charTable['\t'] = 3;
  24.     charTable['\r'] = 4;
  25. #ifdef ANASAZI
  26.     /* the anasazi display mode escape character */
  27.     charTable[0xFE] = (unsigned char)(anasazi ? 5 : 0);
  28. #endif
  29. }
  30.  
  31. struct window * pascal
  32. /* XTAG:createWindow */
  33. createWindow(fileName, row1, col1, row2, col2, topOrBottom, windowType)
  34.     unsigned char *fileName;
  35.     int row1, col1, row2, col2, topOrBottom, windowType;
  36. {
  37.     extern struct window *activeWindow;
  38.     extern struct window *selWindow;
  39.     extern long selBegin, selEnd;
  40.     extern unsigned char msgBuffer[];
  41.     extern unsigned char textColor, selColor;
  42.     extern unsigned char bannerColor, borderColor, elevColor;
  43.     extern int scrRows, scrCols;
  44.     extern struct openFile *files;
  45.     extern unsigned char *userMessages[];
  46.     extern int maxFiles;
  47.     extern int debug;
  48.  
  49.     register struct window *w;
  50.     struct window *w1;
  51.     register int i;
  52.  
  53.     /* find an unused window structure */
  54.     w = NULL;
  55.     for(i = 0; i < maxFiles; i++)
  56.         if( windows[i].state == 0) {
  57.             w = &windows[i];
  58.             break;
  59.         }
  60.     if( w == NULL ) {
  61.         msg(userMessages[OUTOFWINDOWS], 3);
  62.         return NULL;
  63.     }
  64.  
  65.     /* open file to be in the window */
  66.     w->fileId = getFileId(fileName);
  67.     if( w->fileId == -1 )    /* file not found, no not open the window */
  68.         return NULL;
  69.     w->nameOffset = getBaseName(files[w->fileId].origName);
  70.  
  71.     /* insert w into the doubly linked windowList */
  72.     if( windowList == NULL ) {
  73.         w->prevWindow = NULL;
  74.         w->nextWindow = NULL;
  75.         windowList = w;
  76.     } else {
  77.         if( topOrBottom == CRTOP ) {
  78.             windowList->prevWindow = w;
  79.             w->prevWindow = NULL;
  80.             w->nextWindow = windowList;
  81.             windowList = w;
  82.         } else {    /* insert on the bottom */
  83.             w1 = windowList;
  84.             while( w1->nextWindow != NULL )
  85.                 w1 = w1->nextWindow;
  86.             w1->nextWindow = w;
  87.             w->prevWindow = w1;
  88.             w->nextWindow = NULL;
  89.         }
  90.     }
  91.  
  92.     /* set the passed window parameters */
  93.     w->saveRow1 = w->row1 = row1;
  94.     w->saveRow2 = w->row2 = row2;
  95.     w->saveCol1 = w->col1 = col1;
  96.     w->saveCol2 = w->col2 = col2;
  97.  
  98.     /* set the default window parameters */
  99.     w->posTopline = 0;
  100.     w->numTopline = 1;
  101.     w->indent = 0;
  102.  
  103.     if( windowType == 0 )
  104.         /* set the state of unixMode */
  105.         w->state = getUnixState(w->fileId);
  106.     else {
  107.         /* 0x1 => used */
  108.         /* 0xC => no banner and temporary (windowType==1) */
  109.         /* 0x8 => no banner but permanent (windowType==2) */
  110.         w->state = 0x1 + (windowType==1 ? 0xC : 0x8);
  111.     }
  112.     
  113.     /* set up the last row cache */
  114.     w->posCurLast = 0;
  115.     w->lastPosTop = 0;
  116.     w->rowCurLast = 0;
  117.     
  118.     /* set up the window colors */
  119.     w->textCycle = w->borderCycle = 1;
  120.     setWindowColors(w);
  121.  
  122.     /* if there is a file in the window, and the window is */
  123.     /* on top or there is not current selection, */
  124.     /* then move the selection to the new window */
  125.     if( w->fileId != -1 && selWindow == NULL ) {
  126.         /* put the selection at the first char in this window */
  127.         eraseSelection();
  128.         selWindow = w;
  129.         selBegin = 0;
  130.         selEnd = 0;
  131.         if( readChar(w->fileId, 0L) == '\r' ) {
  132.             if( readChar(w->fileId, 1L) == '\n' )
  133.                 selEnd = 1;
  134.         }
  135.     }
  136.  
  137.     redrawWindow(w);
  138.  
  139.     /* make the new window the active window */
  140.     activeWindow = w;
  141.     redoBorders(0);
  142.     updateScreen(0, scrRows-1);
  143.  
  144.     return w;
  145. }
  146.  
  147. void pascal
  148. /* XTAG:setWindowColors */
  149. setWindowColors(w)
  150.     register struct window *w;
  151. {
  152.     extern struct colorCycle colorCycles[];
  153.  
  154.     register int cycle;
  155.  
  156.     cycle = w->textCycle;
  157.     w->textColor = colorCycles[cycle].textColor;
  158.     w->selColor = colorCycles[cycle].selColor;
  159.     cycle = w->borderCycle;
  160.     w->bannerColor = colorCycles[cycle].bannerColor;
  161.     w->borderColor = colorCycles[cycle].borderColor;
  162.     w->elevColor = colorCycles[cycle].elevColor;
  163. }
  164.  
  165. int pascal
  166. /* XTAG:getBaseName */
  167. getBaseName(s)
  168.     unsigned char *s;
  169. {
  170.     register int n;
  171.     register unsigned char ch;
  172.  
  173.     n = strlen(s) - 1;
  174.     while( 1 ) {
  175.         ch = s[n];
  176.         if( ch == ':' || ch == '\\' )
  177.             break;
  178.         if( --n < 0 )
  179.             break;
  180.     }
  181.     return n+1;
  182. }
  183.  
  184. int pascal
  185. /* XTAG:closeWindow */
  186. closeWindow(w, ask, redraw)
  187.     register struct window *w;
  188.     int ask, redraw;
  189. {
  190.     extern struct window *selWindow;
  191.     extern struct window *activeWindow;
  192.     extern long selBegin, selEnd;
  193.     extern int scrRows, scrCols;
  194.     extern int menuLine;
  195.  
  196.     if( closeFile(w->fileId, ask) == -1 )
  197.         return -1;
  198.     w->state = 0;    /* free the window structure */
  199.  
  200.     /* unlink the window from the list of active windows */
  201.     if( w->prevWindow != NULL )
  202.         w->prevWindow->nextWindow = w->nextWindow;
  203.     else    /* must be first on the list -- the top window */
  204.         windowList = w->nextWindow;
  205.     if( w->nextWindow != NULL )
  206.         w->nextWindow->prevWindow = w->prevWindow;
  207.  
  208.     if( redraw ) {
  209.         redrawBox( w->row1, w->col1, w->row2, w->col2);
  210.         updateScreen(w->row1, w->row2);
  211.     }
  212.  
  213.     /* is the selection in this window? */
  214.     if( w == selWindow ) {
  215.         /* move the selection to the top window */
  216.         selWindow = windowList;
  217.         if( selWindow != NULL ) {
  218.             selBegin = 0;
  219.             selEnd = 0;
  220.             if( readChar(selWindow->fileId, 0L) == '\r' ) {
  221.                 if( readChar(selWindow->fileId, 1L) == '\n' )
  222.                     selEnd = 1;
  223.             }
  224.             if( redraw )
  225.                 redrawWindow(selWindow);
  226.         }
  227.     }
  228.     /* is this the active window? */
  229.     if( w == activeWindow ) {
  230.         activeWindow = windowList;
  231.         redoBorders(0);
  232.         if( redraw )
  233.             updateScreen((menuLine > 0 ? 1 : 0), scrRows-1);
  234.     }
  235.     return 0;
  236. }
  237.  
  238. void pascal
  239. /* XTAG:topWindow */
  240. topWindow(w)
  241.     register struct window *w;
  242. {
  243.     extern struct window *activeWindow;
  244.  
  245.     if( w != windowList ) {
  246.         w->prevWindow->nextWindow = w->nextWindow;
  247.         if( w->nextWindow != NULL )
  248.             w->nextWindow->prevWindow = w->prevWindow;
  249.         w->prevWindow = NULL;
  250.         windowList->prevWindow = w;
  251.         w->nextWindow = windowList;
  252.         windowList = w;
  253.     }
  254.     activeWindow = w;
  255. }
  256.  
  257. void pascal
  258. /* XTAG:redrawWindow */
  259. redrawWindow(w)
  260.     register struct window *w;
  261. {
  262.     /* set up the screen map and draw the window */
  263.     setMap(w->row1, w->col1, w->row2, w->col2, 1, 0x07);
  264.     maskTop(w);
  265.     drawWindow(w);
  266. }
  267.  
  268. int pascal
  269. /* XTAG:moveWindow */
  270. moveWindow(w, row1, col1, row2, col2)
  271.     register struct window *w;
  272.     int row1, col1, row2, col2;
  273. {
  274.     extern int scrRows, scrCols;
  275.     extern struct window *activeWindow;
  276.     extern unsigned char msgBuffer[];
  277.     extern int topOnFind;
  278.  
  279.     int r1, c1, r2, c2;
  280.     int redoAll;
  281.  
  282.     /* if we have to erase the old active window */
  283.     /* just redo the whole screen*/
  284.     redoAll = (w != activeWindow);
  285.  
  286.     /* fix impossible corners */
  287.     if( row1 < 0 )
  288.         row1 = 0;
  289.     if( row2 > (scrRows-1) )
  290.         row2 = (scrRows-1);
  291.     if( col1 < 0 )
  292.         col1 = 0;
  293.     if( col2 > (scrCols-1) )
  294.         col2 = (scrCols-1);
  295.  
  296.     /* do not allow very small windows */
  297.     if( row2 < row1+2 || col2 < col1+10 )
  298.         return 1;
  299.  
  300.     /* find the bound of the redrawing  */
  301.     r1 = min(row1, w->row1);
  302.     c1 = min(col1, w->col1);
  303.     r2 = max(row2, w->row2);
  304.     c2 = max(col2, w->col2);
  305.     
  306.     /* only these have to change in the window structure */
  307.     w->row1 = row1;
  308.     w->col1 = col1;
  309.     w->row2 = row2;
  310.     w->col2 = col2;
  311.  
  312.     if( redoAll ) {
  313.         r1 = 0;
  314.         c1 = 0;
  315.         r2 = scrRows - 1;
  316.         c2 = scrCols - 1;
  317.     }
  318.  
  319.     /* redraw all the windows that might have changed */
  320.     redrawBox(r1, c1, r2, c2);
  321.     updateScreen(r1, r2);
  322.  
  323.     return 0;
  324. }
  325.  
  326. void pascal
  327. /* XTAG:redrawBox */
  328. redrawBox(row1, col1, row2, col2)
  329.     int row1, col1, row2, col2;
  330. {
  331.     extern struct window *windowList;
  332.     extern unsigned char textColor;
  333.     extern int scrRows, scrCols;
  334.     extern int menuLine;
  335.     extern int menuShowing;
  336.     extern unsigned char toplineVector[];
  337.     extern int debug;
  338.  
  339.     register struct window *w1;
  340.     int lowRow, highRow, n;
  341.  
  342.     /* set up the screen map and clear the screen area */
  343.     setMap(row1, col1, row2, col2, 2, 0x7);
  344.     
  345.     /* restore the menu line if necessary */
  346.     if( (menuLine > 0 && row1 == 0)
  347.      || (menuLine < 0 && row2 == (scrRows-1)) ) {
  348.          /* find the first top line menu (to be the de